package design.pattern.Command.factory;

import design.pattern.Command.inter.CommandHandle;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CommandFactory {
  private static Map<String, List<CommandHandle>> map = new HashMap<>();
  
  public static void register(String type, CommandHandle handle) {
    List<CommandHandle> list;
    
    if (!map.containsKey(type))
      map.put(type, (list = new ArrayList<>()));
    else
      list = map.get(type);
    
    // 集合 中添加事件
    list.add(handle);
  }
  
  public static List<CommandHandle> get(String type) {
    return map.get(type);
  }
}
